# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: script_5.py
@time: 2024/11/2 21:52 
@desc: 

"""
from scripts.base_script import BaseScript
from sdk.utils.util_class import PathParser
from sdk.utils.util_bos import BosOnline
from sdk.utils.util_encrypt import EncryptProcess


class Solution(BaseScript):
    """

    """

    def __init__(self):
        super(Solution, self).__init__()
        self.desc = f"script_BOS_Upload"
        print(self.desc)
        self.bos = BosOnline()
        self.ep = EncryptProcess()

    def upload_files(self, input_file):
        """

        :param input_file:
        :return:
        """
        uid = self.ep.make_uuid()
        obj = PathParser(input_file)
        bos_url = self.make_new_bos_url(uid, folder=self.tmp_folder, name=f"{obj.name}.{obj.tail}")
        self.bos.upload(bos_url, input_file)

        bos_dw_url = self.bos.get_download_url(bos_url)
        self.save_result(self.folder.merge_path([self.tmp_folder, r"result_bos_upload.txt"]), [bos_dw_url], ["bos"])

        self.zip.zip_files(self.tmp_folder, self.zip_file)
        self.folder.remove(folder=self.tmp_folder)
        return self.zip_name

    def process(self, data):
        """

        :return:
        """
        data["Desc"] = self.desc
        self.check_keys(data, ["input_file"])
        input_file = self.tmp_upload_path + data["input_file"]
        download_file = ""
        download_file = self.upload_files(input_file)
        download_file = download_file.replace('\\', '/')
        data["ScriptResults"] = download_file

        return data

